package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.domain.bank.SavingAccount;
import com.acme.bankapp.exceptions.BankException;
import com.acme.bankapp.exceptions.ClientExistsException;
import com.acme.bankapp.exceptions.IllegalAmountArgumentException;
import com.acme.bankapp.exceptions.NotEnoughFundsException;
import com.acme.bankapp.exceptions.OverDraftLimitExceededException;
import com.acme.bankapp.service.bank.BankService;

public class BankAplication {

	private static boolean addClientInBank(Bank bank, Client client) {
		
		try {
			BankService.addClient(bank, client);
			return true;
		} catch (ClientExistsException e) {
			System.out.println("Client already exist");
		} catch (BankException e) {
			System.out.println(e);
		}
		return false;
	}
	
	
	public static void main(String[] args) throws IllegalAmountArgumentException, ClientExistsException {
		
		Bank bank = new Bank();

		addClientInBank(bank, new Client("Ivan", Gender.MALE,   new SavingAccount  (110)      ) );
		addClientInBank(bank, new Client("Petr", Gender.MALE,   new CheckingAccount(120, 100) ) );
		addClientInBank(bank, new Client("Anna", Gender.FEMALE, new SavingAccount  (130)      ) );
		addClientInBank(bank, new Client("Ivan", Gender.MALE,   new SavingAccount  (110)      ) );
		addClientInBank(bank, new Client("Yana", Gender.FEMALE, new CheckingAccount(140, 50 ) ) );

		try {
			
			for (Client client: bank.getClients() ) {
				BankService.modifyBank(bank, client, 100);
				System.out.println(client.toString());
			}
			
        } catch (OverDraftLimitExceededException e) {
                System.out.println(
                		"OverDraftLimitExceededExceptione: limit is: " + e.getMaximumAmountToWithdraw()
                        + " account is: " + e.getAccout());
        } catch (NotEnoughFundsException e) {
                System.out.println("NotEnoughFundsException: limit is: "
                                + e.getAmount());
        } catch (BankException e) {
                System.out.println(e);
        }
		
		System.out.println(
				bank.getClients().get(0).equals( bank.getClients().get(1) ) 
				+ "\n" + 
				bank.getClients().get(0).equals( bank.getClients().get(3) ));
	}
}
